<template>
  <div>
    <div>
      {{ val }}
      <button @click="change1">改1</button>
    </div>

    <div>
      {{ flag }}
      <button @click="change2">改2</button>
    </div>
  </div>
</template>

<script setup lang="ts">
const props = withDefaults(
  defineProps<{
    val: number
    flag?: boolean
  }>(),
  {
    flag: false
  }
)

const emit = defineEmits<{
  (e: 'cg1', val: number): void
  (e: 'cg2', val: boolean): void
}>()

const change1 = () => {
  emit('cg1', 100)
}

const change2 = () => {
  emit('cg2', true)
}
// const { val, flag = false } = defineProps<{
//   val: number
//   flag?: boolean
// }>()
</script>

<style lang="scss" scoped></style>
